using System.Collections.Generic;
using Project.Configs;
using Project.Models;
using Project.ViewModels;
using Project.Views;
using UnityEngine;

namespace Project.EntryPoints
{
    public class SceneEntryPoint : MonoBehaviour
    {
        private ItemConfigsStorage _itemConfigsStorage;
        private Inventory _inventory;
        private WorldInventory _worldInventory;
        private InventoryViewModel _inventoryViewModel;
        private WorldInventoryViewModel _worldInventoryViewModel;

        [SerializeField] private InventoryConfig _inventoryConfig;
        [SerializeField] private List<ItemConfig> _itemConfigs;
        [Space]
        [SerializeField] private RootUIView _rootUIView;
        [SerializeField] private InventoryUIView _inventoryUIView;
        [SerializeField] private WorldInventoryUIView _worldInventoryUIView;

        private void Start()
        {
            InitializeModels();
            InitializeViewModels();
            InitializeViews();
        }

        private void InitializeModels()
        {
            _itemConfigsStorage = new ItemConfigsStorage().Add(_itemConfigs);
            _worldInventory = new WorldInventory(_itemConfigsStorage);
            _inventory = new Inventory(
                _inventoryConfig.MinQuantityOfSlots, 
                _inventoryConfig.MaxQuantityOfSlots,
                _inventoryConfig.MinQuantityOfSlots, 
                _itemConfigsStorage);

            _worldInventory.RegisterInventory(_inventory);
        }

        private void InitializeViewModels()
        {
            _inventoryViewModel = new InventoryViewModel(_inventory, _itemConfigsStorage);
            _worldInventoryViewModel = new WorldInventoryViewModel(_worldInventory, _itemConfigsStorage);
        }

        private void InitializeViews()
        {
            _inventoryUIView.Initialize(_inventoryViewModel, _rootUIView);
            _worldInventoryUIView.Initialize(_worldInventoryViewModel, _rootUIView);
        }
    }
}
